#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 5010;

int s[N], n;
ll f[N], v[N];

void solve() {
	n = in;
	rep(i, 1, n) v[i] = 0, f[i] = 0, s[i] = in;
	f[0] = 0;
	rep(i, 1, n) {
		f[i] = f[i - 1];
		f[i] += max(s[i] - 1 - v[i], 0ll);
		int st = 2;
		rep(j, st, s[i]) { if(j + i > n) break; v[j + i]++; }
		if(v[i] >= s[i]) { v[i + 1] += v[i] - s[i] + 1; }
	}
	printf("%lld\n", f[n]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    int T = in; while(T--) solve(); return 0;
}
